package com.jzt.qf.service.impl;
/**
 * 　* @description:销售单service实现类
 * 　* @author zxy
 * 　* @date 2020-07-23 14:59
 *
 */

import com.alibaba.fastjson.JSON;
import com.jzt.qf.beans.HttpResult;
import com.jzt.qf.beans.UploadBase;
import com.jzt.qf.beans.jztBean.InStockPlan_Upload;
import com.jzt.qf.beans.jztBean.OutStockPlan_Upload;
import com.jzt.qf.beans.qfBean.ZxyUploadbillJzt;
import com.jzt.qf.dao.SaleBillDao;
import com.jzt.qf.dao.UploadbillJztDao;
import com.jzt.qf.https.JztApi;
import com.jzt.qf.service.SaleBillService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class SaleBillServiceImpl implements SaleBillService {
    @Autowired
    private SaleBillDao saleBillDao;
    @Resource
    private UploadbillJztDao uploadbillJztDao;
    @Resource
    private JztApi jztApi;
    @Override
    public HttpResult uploadSaleBill(String billCode) {
        log.info("上传销售单SaleBillServiceImpl访问成功");
        //获取销售订单
        List<OutStockPlan_Upload> outStockPlan_uploads = saleBillDao.getSaleBill_Upload(billCode);
        log.info("销售单上传json串" + JSON.toJSONString(outStockPlan_uploads));
        HttpResult httpResult = jztApi.HttpRequest(
                new UploadBase("ck", "saveData", outStockPlan_uploads));
        log.info("上传销售单返回数据" + JSON.toJSONString(httpResult));
        //TODO 修改中间库数据
        if (httpResult.isFlag()) {
            for (OutStockPlan_Upload outStockPlan_upload : outStockPlan_uploads) {
                ZxyUploadbillJzt zxyUploadbillJzt = new ZxyUploadbillJzt();
                zxyUploadbillJzt.setBillcode(outStockPlan_upload.getBiz_Bill_No());
                zxyUploadbillJzt.setOrd(Integer.parseInt(outStockPlan_upload.getBill_Dtl_Id()));
                zxyUploadbillJzt.setBilltype(11);
                uploadbillJztDao.updateFlags(zxyUploadbillJzt);
            }
            saleBillDao.updateGspOutBillOutQty0(billCode);
        }
        return httpResult;
    }
}
